package com.hedl.classroom.feignclient.impl;

import com.hedl.classroom.feignclient.CourseIndex;
import com.hedl.classroom.feignclient.SearchServiceClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author Big Watermelon
 * @description
 * @date 2023/11/27/1:16
 */
@Slf4j
@Component
public class SearchServiceClientFallbackFactory implements FallbackFactory<SearchServiceClient> {

    @Override
    public SearchServiceClient create(Throwable cause) {
        return new SearchServiceClient() {
            @Override
            public Boolean add(CourseIndex courseIndex) {
                log.error("添加课程索引发生熔断，索引信息：{},熔断异常：{}",courseIndex,cause.toString(),cause);

                //走降级就返回false
                return false;
            }
        };
    }
}
